<?php

/**
 * RP System
 *
 * @version 1.0
 * @copyright 2004 Ron Planken
 */

class team {

	function get($team_id = -1) {
		
		global $dbh;
		
		if ($team_id == -1) {
			$query ='SELECT  t.team_id
							,t.team_image
							,t.team_name
							,t.team_order
					   FROM team t
					  ORDER by t.team_order ASC
							';
		} else {
			$query ="SELECT  t.team_id
							,t.team_image
							,t.team_name
							,t.team_order
					   FROM team t
					  WHERE  t.team_id = $team_id
					  ORDER by t.team_order ASC
							";
		}
		
		$teams = selectMultiQuery($query, $dbh);
		
		return $teams;
	}
	

	function getOption() {
		global $dbh;
		
			$query ='SELECT t.team_id
							,t.team_name
							,t.team_order
					   FROM team t
					  ORDER by t.team_order DESC
							';
		
		
			$teams = selectSingleTextQuery($query, $dbh);
			
			return $teams;
			
	}
	
	function save($team_id = 0, $team_name = "", $team_image = "", $team_order =0) {
		
		$team_name = secure_string($team_name);
		
		$team_image = secure_string($team_image);
		
		global $dbh;
		
		if ($team_id == 0) {
			$query ="INSERT INTO team
						   (team_name
						   ,team_image
						   ,team_order)
					VALUES ($team_name
						   ,$team_image
						   ,$team_order)
							";
			$status = InsertQuery($query, $dbh);
		} else {
			$query ="UPDATE team
						SET team_name = $team_name
						   ,team_image = $team_image
						   ,team_order = $team_order
					  WHERE team_id = $team_id
							";
			$status = UpdateQuery($query, $dbh);
		}
		
		echo $query;
		
		return $status;
		
	}
	

	function remove($team_id = 0) {

		global $dbh;

		$team_id = secure_int($team_id);

		$query ="DELETE FROM team
				  	   WHERE team_id = $team_id;
							";
		$status = UpdateQuery($query, $dbh);



		return $status;
	}
	
}
?>